package main

import (
	"fmt"
	"unsafe"
)

//struct defined,initialize
type Person struct{
   name string
   age int
}
type Abc struct {
    age rune
}
// Person or *Person
func (p Person) eat(s string) string {
	return fmt.Sprintf("%s is eating %s",p.name,s)
}
func (p Person) Key() string {
	return fmt.Sprintf("%s is eating",p.name)
}
type lucy int

func (lucy) lucci()  {
	fmt.Println("lllllaaa")
}
func (lucy) close()  {
	fmt.Println("close")
}

type closable interface {
	close()
}

func main() {
	// ptr
	var ptr1 *int
	fmt.Printf("%p , %v \n", ptr1, ptr1)
	//panic: runtime error: invalid memory address or nil pointer dereference
	//fmt.Printf("%p , %v %v\n", ptr1, ptr1, *ptr1)
	int1 := 123
	ptr1 = &(int1)
	fmt.Printf("%p , %v\n", ptr1, ptr1)
	fmt.Println(ptr1, *ptr1)

    person1:=Person{"zhsadddddddddddddddddddsaffasdfdffffffffffffffn",2}
    person11:=Person{"zhsan",2}
    person2:=&Person{"lisi",18}
    person3:=Person{}
	var person4 Person //定义就初始化 零值化 person3==person4 比较默认比较内容吗？
	person5:=new(Person)
	fmt.Println(person3.eat("apple"))
	fmt.Println(person2.eat("apple"))
	//person3.name="hello"
	fmt.Println(person1)
	fmt.Println(person2)
	fmt.Printf("%v\n",person2.name)
	fmt.Printf("%v\n",person3)  //{hello 0}
	fmt.Printf("%v\n",person4)
	fmt.Println(person4==person3)
	fmt.Println(person4==person1)
	fmt.Println(person11==person1)
	fmt.Println(person5)
	fmt.Println(person3)
	fmt.Printf("%#v , %v\n",&person3,&person3)
	fmt.Printf("%v\n",unsafe.Sizeof(person3))
	fmt.Printf("%v\n",unsafe.Sizeof(&person1))
	fmt.Printf("%v\n",unsafe.Sizeof(person1.age))
	fmt.Printf("%v\n",unsafe.Sizeof(person1.name))
	fmt.Printf("%v\n",unsafe.Sizeof("asdf"))
	fmt.Printf("%v\n",unsafe.Sizeof(Abc{}))
	fmt.Println(person3==person4)

	var aa lucy=3
	aa.lucci()

	var map1 map[string]int
	//map1["hello"]=3
	map2 := make(map[int]string)
	map2[3]="hello"
	map3 := make(map[Person]string)
	map3[person3]="helloasfaaa"
	map3[person1]="helloasfasfdlolo"
	//map4 := make(map[[]int]string)
	//arr1 :=[]int{1,23}
	//map4[arr1]="helloasfasfd"
	fmt.Println(map1["heads"])
	fmt.Println(map1["headsdsaflolo"])
	fmt.Println(map2[3])
	fmt.Println(map3[person4]," cmdb")
	fmt.Println(map3)
	fmt.Println(map3[person3])
	//fmt.Println(map4)

}
